<?php
session_start();

// 检查用户是否已登录
if (!isset($_SESSION['user_id'])) {
    header('Location: login.php');
    exit;
}

require_once 'database.php';
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>山阳区培训管理 - 
        <?php 
            // 根据不同页面设置标题
            if (isset($pageTitle)) {
                echo htmlspecialchars($pageTitle);
            } else {
                echo '首页';
            }
        ?>
    </title>
    <!-- 引入Bootstrap CSS -->
    <link href="https://cdn.staticfile.net/bootstrap/5.3.2/css/bootstrap.min.css" rel="stylesheet">
    <!-- 自定义样式 -->
    <style>
        body {
            min-height: 100vh;
            display: flex;
            flex-direction: column;
        }
        .navbar {
            margin-bottom: 1rem;
        }
        .footer {
            margin-top: auto;
            padding: 1rem 0;
            background-color: #f8f9fa;
        }
        .nav-item.active a {
            font-weight: bold;
        }
    </style>
</head>
<body>
    <nav class="navbar navbar-expand-lg navbar-dark bg-primary">
        <div class="container">
            <a class="navbar-brand" href="index.php">培训管理</a>
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarNav">
                <ul class="navbar-nav me-auto">
                    <li class="nav-item">
                        <a class="nav-link" href="teachers.php">教师管理</a>
                    </li>
                    <?php if (isset($_SESSION['username']) && $_SESSION['username']=='admin'){ ?>
                    <li class="nav-item">
                        <a class="nav-link" href="users.php">账号管理</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="training_edit.php">添加培训</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="report_cost.php">费用统计</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="report_training.php">培训汇总</a>
                    </li>
                    <?php } ?>
                </ul>
                <?php if (!isset($_SESSION['user_id'])){ ?>
                    <a href="login.php" class="btn btn-outline-light">登录</a>
                <?php } else { ?>
                    <a href="change_password.php" class="btn btn-outline-light">设置密码</a>
                    <a href="logout.php" class="btn btn-outline-light">退出登录</a>
                <?php } ?>
            </div>
        </div>
    </nav>

    <div class="container mt-4">
        